/*
 * @Autor: dingxiaolin
 * @Date: 2020-12-10 13:50:52
 * @LastEditors: dingxiaolin
 * @LastEditTime: 2020-12-15 16:40:08
 */
package com.dxl.entity;

import com.alibaba.excel.annotation.ExcelProperty;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.baomidou.mybatisplus.annotation.Version;
import com.dxl.entity.groups.Insert;
import com.dxl.entity.groups.Update;
import com.dxl.enums.SexEnum;
import com.dxl.utils.converter.SexConverter;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.validator.constraints.Length;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Null;
import java.util.Date;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class Admin {
    @ApiModelProperty(value = "自增id")
    // 国际化 header 上带 Accept-Language:zh-CN 或 en-US
    @Null(message = "{error.notnull}", groups = {Insert.class})
    @NotNull(message = "更新时id不能为空", groups = {Update.class})
//    @JSONField(serialize = false) //忽略某属性 如果使用fastjson需要用左边这个方法，没用fastjson 就@@JsonIgnore
    @TableId(type= IdType.AUTO)
    //@TableId("uuid") //可以映射到数据库的主键UUID
    private Long id;
    @ApiModelProperty("用户名")
    @ExcelProperty(value = "用户名",index=0)
    @NotBlank(message = "用户名不可以为空")
    private String userName;
    @ApiModelProperty("密码")
    @ExcelProperty(value = "密码",index=1)
    @Length(min = 6, max = 12, message = "请输入6-12位密码")
    private String passWord;
    @ExcelProperty(value = "性别",converter = SexConverter.class)
    @ApiModelProperty(value = "性别:1男 2女",required = true,allowableValues = "1,2")
    private SexEnum sex;
    @ExcelProperty(value = "创建时间",index = 2)
    @ApiModelProperty(value = "创建时间", hidden = true)
    // @TableField(fill = FieldFill.INSERT)
    private Date createTime;
    @ExcelProperty(value = "更新时间",index = 3)
    @ApiModelProperty(value = "更新时间", hidden = true)
    // @TableField(fill = FieldFill.UPDATE)
    private Date  updateTime;
    @ApiModelProperty(value = "逻辑删除", hidden = true)
    @TableLogic
    //软删除，默认是deleted为0，删除其实是update，操作后为1，【YML配置0和1】查询会自动带上deleted为0的条件。
    private Integer deleted;
    @ApiModelProperty(value = "乐观锁", hidden = true)
    @Version
    private Integer version;
}
